#include "indexpagewindow.h"

IndexPageWindow::IndexPageWindow(QWidget *parent) : QWidget(parent)
{
    setWindowTitle("lanxiao");
    resize(800,600);
    //通过相对路径加载图像
    //w.setWindowIcon(QIcon("../qtspace/th.jpg"));

    //通过资源文件加载图像
    setWindowIcon(QIcon(":/new/prefix1/img/th.jpg"));

    //实例化按钮对象,将w作为父组件
    QPushButton *Button1 = new QPushButton(this);
    //获取组件大小，并打印输出
    qDebug()<<"size:"<<Button1->size();
    //Button1.setGeometry(0,0,100,34);
    QPushButton *Button2 = new QPushButton("最大化",this);
    //修改组件大小
    Button2->resize(Button1->size());
    Button2->move(50,0);

    QObjectTree *normal = new QObjectTree(this);
    normal->move(150,0);

    iniWindow();
    QObject::connect(Button1,SIGNAL(clicked(bool)),this,SLOT(close()));
    QObject::connect(Button2,SIGNAL(clicked(bool)),this,SLOT(showMaximized()));
    QObject::connect(normal,SIGNAL(clicked(bool)),this,SLOT(showMinimized()));
}

void IndexPageWindow::iniWindow()
{
    gender = new QGroupBox("性别",this);
    manButton = new QRadioButton("男",gender);
    womenButton = new QRadioButton("女",gender);

    int starty = 40;
    int level = 10;
    int m_width = manButton->width();
    manButton->move(0,starty);
    womenButton->move(level+m_width,starty);
    gender->move(0,starty);

    //是否婚配
    marryBox = new QGroupBox("婚否",this);
    ismarry = new QRadioButton("已婚",marryBox);
    nomarry = new QRadioButton("未婚",marryBox);

    marryBox->move(0,starty * 4);
    ismarry->move(0,starty);
    nomarry->move(level+m_width,starty);
    QObject::connect(manButton,SIGNAL(toggled(bool)),this,SLOT(displayGender()));

    commitButton = new QPushButton("提交",this);
    commitButton->move(0,starty * 8);
    QObject::connect(commitButton,SIGNAL(clicked(bool)),this,SLOT(commitInfo()));

    passwdButton = new QLineEdit("Enter your passwd",this);
    passwdButton->move(0,starty *9);

    txtButton = new QTextEdit(this);
    txtButton->move(marryBox->width()+150,starty *4);

    timeButton = new QDateTimeEdit(this);
    timeButton->move(0,starty *10);
}

void IndexPageWindow::displayGender()
{
    if(manButton->isChecked())
    {
        qDebug()<<"男";
    }else
    {
        qDebug()<<"女";
    }
}

void IndexPageWindow::commitInfo()
{
    QString gender;
    if(manButton->isChecked())
    {
        gender = "男";
    }else
    {
        gender = "女";
    }

    QString marry;
    if(ismarry->isChecked())
    {
        marry = "已婚";
    }else
    {
        marry = "未婚";
    }

    qDebug()<<"性别："<<gender<<","<<"婚配情况："<<marry;
}
